import pandas as pd
path = 'C:\\Users\dell\Downloads\gaze.csv'
with open(path) as file:
    data = pd.read_csv(file)

#lab4
time = data['gaze_timestamp']
numbers = len(data) - 1
total = 0
for i in range(numbers):
    a = time.iloc[i + 1]
    b = time.iloc[i]
    c = a - b
    total = total + c
    mean = total / numbers
hz = 1 / mean
print(hz,"hz")

#lab1
data = data[data['confidence'] >= 0.9]
print("1:",len(data))

#lab3
mean_x = 0.41023
mean_y = 0.43832
sigma_x = 0.209525812
sigma_y = 0.216087662
a = mean_x + 3*sigma_x
b = mean_x - 3*sigma_x
c = mean_y + 3*sigma_y
d = mean_y - 3*sigma_y
data = data[(data['norm_pos_x'] > b) & (data['norm_pos_x'] < a)]
data = data[(data['norm_pos_y'] > d) & (data['norm_pos_x'] < c)]
print("2:",len(data))

#lab5
time = 88150.78
while time < 88151.28:
    e = []
    stamp = data['gaze_timestamp']
    for i in range(len(data)):
        a = stamp.iloc[i]
        b = a - time
        e.append(b)
        location = e.index(min(e))
    print(data.iloc[location])
    time = time + 0.02

#lab3
data['gaze_timestamp'] = pd.to_datetime(data['gaze_timestamp'],unit = 's', origin = pd.Timestamp('1970-01-02T17:44:30.225707'))